#全0数列
#Numpy.zeros(shape, dtype=None, order='C')
#shape：数组的维度，如(2,3)
#dtype：数据类型，如int32,float64

import numpy as np
a = np.zeros((2,3))
print(a)           #[[ 0.  0.  0.]
                  # [ 0.  0.  0.]]

b = np.zeros((2,2,3))    #三维 块、行、列
print(b)           #[[[ 0.  0.  0.]
                  #  [ 0.  0.  0.]]

                  # [[ 0.  0.  0.]
                  #  [ 0.  0.  0.]]]

#zeros_like返回具有与给定数组相同的形状的零数组
a1 = np.array([[1,2,3],[4,5,6]])
b1 = np.zeros_like(a1)
print(b1)            # [[ 0.  0.  0.]
                    #  [ 0.  0.  0.]]

print('--------------------------------------------------------------')

#Numpy数组属性，比较重要的ndarray对象属性有：
#ndarray.ndim: 数组维度,秩
#ndarray.shape: 数组形状
#ndarray.size: 数组元素个数
#ndarray.dtype: 数组元素类型
#ndarray.itemsize: 数组元素字节数

#reshape: 改变数组的形状
a = np.arange(1,10).reshape(3,3)
print(a)    #[[1 2 3]
          # [4 5 6]
          # [7 8 9]]

#resize: 改变数组的形状,自动补充完整
a = np.array([[0,1],[2,3]])
b = np.resize(a,(2,3))
print(b)      # [[0 1 2]
              # [3 0 0]]
a.resize((2,3),refcheck=False)
print(a)       # [[0 1 2]
              # [3 0 0]]


#astype: 改变数组元素类型,原数据类型不改变
a = np.array([1,2,3])
b = a.astype(np.float64)
c = a.astype(np.int32)
d = a.astype(np.string_)
print(b)    # [ 1.  2.  3.]
print(c)    # [1 2 3]
print(d)    # ['1' '2' '3']


#itemsize: 获取数组元素字节数
a = np.array([1,2,3])
print(a.itemsize,a.dtype)  # 4 int32
